#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright 2015 TUBITAK/UEKAE
# Licensed under the GNU General Public License, version 2.
# See the file http://www.gnu.org/copyleft/gpl.txt.

from inary.actionsapi import autotools
from inary.actionsapi import inarytools
from inary.actionsapi import shelltools
from inary.actionsapi import get

def setup():
    libdir = "lib"
    if get.buildTYPE() == "emul32":
        shelltools.export("CC","gcc -m32")
        shelltools.export("CXX","g++ -m32")
        shelltools.reset_env()
        shelltools.export("LDFLAGS","-m32")
        shelltools.export("PKG_CONFIG_PATH","/usr/lib32/pkgconfig")
        libdir = "lib32"
    autotools.configure("--prefix=/ \
                --with-rootprefix=/ \
		--includedir=/usr/include \
		--libdir=/{} \
		--enable-split-usr \
		--enable-manpages \
		--enable-kmod \
		--disable-selinux \
		--bindir=/bin".format(libdir))

    inarytools.dosed("libtool", " -shared ", " -Wl,-O1,--as-needed -shared ")

def build():
    autotools.make()

def install():
    autotools.rawInstall("-j1 DESTDIR=%s" % (get.installDIR()))
    # emul32 stop here
    if get.buildTYPE() == "emul32":
        return
    else:
        # Create /etc/udev/rules.d for backward compatibility
        inarytools.dodir("/etc/udev/rules.d")
